<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编程导航后台登录</title>
    <link rel="stylesheet" href="./css/style.css">
    <style>
        :root {
            --primary-color: #4285f4;
            --secondary-color: #f1f3f4;
            --text-color: #202124;
            --border-radius: 8px;
            --box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            padding: 0;
        }

        .container {
            background-color: white;
            padding: 2rem;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            width: 100%;
            max-width: 400px;
        }

        h2 {
            color: var(--primary-color);
            text-align: center;
            margin-bottom: 1.5rem;
        }

        .form-group {
            margin-bottom: 1.2rem;
        }

        label {
            display: block;
            margin-bottom: 0.5rem;
            color: var(--text-color);
            font-weight: 500;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid #ddd;
            border-radius: var(--border-radius);
            box-sizing: border-box;
            transition: border-color 0.3s;
        }

        input[type="text"]:focus,
        input[type="password"]:focus {
            outline: none;
            border-color: var(--primary-color);
        }

        button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 0.8rem 1.5rem;
            border-radius: var(--border-radius);
            cursor: pointer;
            width: 100%;
            font-size: 1rem;
            transition: background-color 0.3s;
            margin-top: 0.5rem;
        }

        button:hover {
            background-color: #3367d6;
        }

        button:last-child {
            background-color: #34a853;
        }

        button:last-child:hover {
            background-color: #2d8e4a;
        }

        .form-group img {
            height: 36px;
            cursor: pointer;
        }
    </style>
    <!--引入vue相关的js文件-->
    <script src="./js/vue.js"></script>
    <script src="./js/axios.min.js"></script>
<body>
    <div class="container" id="app">
        <h2>登录</h2>
        <form id="loginForm" action="javascript:void(0)">
            <div class="form-group">
                <label for="username">用户名</label>
                <input v-model="loginData.username" type="text" id="username" name="username" required>
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input v-model="loginData.pwd" type="password" id="password" name="password" required>
            </div>
            <div class="form-group">
                <label for="captcha">验证码</label>
                <div style="display: flex; gap: 10px; align-items: center;">
                    <input v-model="loginData.captcha" type="text" id="captcha" name="captcha" required>
                    <img src="/pns/captcha" alt="..." onclick="this.src=this.src+'?'">
                </div>
            </div>
            <button @click="login">登录</button>
            <button @click="goToRegister">注册</button>
        </form>
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                loginData:{
                    username:'',
                    pwd:'',
                    captcha:''
                }
            },
            methods:{
                login:function () {
                    axios({
                        url:"/pns/login",
                        method:"get",
                        params: this.loginData
                    }).then(result=>{
                        let code = result.data.code;
                        if (code == "200"){
                            //登录成功，将用户信息保存到js缓存
                            let data = result.data.data;
                            localStorage.setItem("account",JSON.stringify(data));
                            //跳转到main.html
                            location.href="/pns/main.html"
                        }
                    });
                },
                goToRegister: function() {
                    location.href = "/pns/register.html";
                }
            }
        });
    </script>
</body>
</html>